import { param2Obj } from '@/utils';

const faker = require('faker');

faker.locale = 'zh_CN';

const ConCodeList = [
  { id: '0001', name: '物料编号' },
  { id: '0002', name: '批号' },
  { id: '0003', name: '序列号' },
  { id: '0004', name: '仓库' },
  { id: '0005', name: '仓位' },
  { id: '0006', name: '供应商' },
  { id: '0007', name: '客户' },
  { id: '0008', name: '外购入库单' },
  { id: '0009', name: '委外入库单' },
  { id: '0010', name: '生产品入库单' },
  { id: '0011', name: '生产退料入库单' },
  { id: '0012', name: '销售退货入库单' },
  { id: '0013', name: '调拨入库单' },
  { id: '0014', name: '盘盈入库单' },
  { id: '0015', name: '组装拆卸入库单' },
  { id: '0016', name: '其它入库单' },
  { id: '0017', name: '外购退料出库单' },
  { id: '0018', name: '委外出库单' },
  { id: '0019', name: '销售出库单' },
  { id: '0020', name: '生产补料出库单' },
  { id: '0021', name: '生产领料出库单' },
  { id: '0022', name: '调拨出库单' },
  { id: '0023', name: '盘盈出库单' },
  { id: '0024', name: '组装拆卸出库单' },
  { id: '0025', name: '其它出库单' },
  { id: '0026', name: '盘点单' },
  { id: '0027', name: '调拨单' },
  { id: '0028', name: '组装拆卸单' },
  { id: '0029', name: '采购申请单' },
  { id: '0030', name: '采购订单' },
];
const DataSource1 = [
  { id: 'D0001', name: '年YYYY' },
  { id: 'D0002', name: '月MM' },
  { id: 'D0003', name: '日DD' },
  { id: 'D0004', name: '时HH' },
  { id: 'D0005', name: '分mm' },
  { id: 'D0006', name: '秒SS' },
  { id: 'D0007', name: '一级部门' },
  { id: 'D0008', name: '存货类别' },
  { id: 'D0009', name: '物料自定义分类' },
  { id: 'D0010', name: '流水号' },
  { id: 'D0011', name: '固定值' },
];
const DataSource2 = [
  { id: 'D0001', name: '年YYYY' },
  { id: 'D0002', name: '月MM' },
  { id: 'D0003', name: '日DD' },
  { id: 'D0004', name: '时HH' },
  { id: 'D0005', name: '分mm' },
  { id: 'D0006', name: '秒SS' },
  { id: 'D0007', name: '一级部门' },
  { id: 'D0008', name: '存货类别' },
  { id: 'D0010', name: '流水号' },
  { id: 'D0011', name: '固定值' },
];
const DataSource3 = [
  { id: 'D0010', name: '流水号' },
  { id: 'D0011', name: '固定值' },
];
const DataSource4 = [
  { id: 'D0001', name: '年YYYY' },
  { id: 'D0002', name: '月MM' },
  { id: 'D0003', name: '日DD' },
  { id: 'D0004', name: '时HH' },
  { id: 'D0005', name: '分mm' },
  { id: 'D0006', name: '秒SS' },
  { id: 'D0010', name: '流水号' },
  { id: 'D0011', name: '固定值' },
];
const codeDetail = [
  {
    id: '80001',
    ordinal: 1,
    datasourceId: 'D0010',
    dataSourceName: '流水号',
    digits: 6,
    constant: 'PH',
    snCurrent: 208,
    snBeginning: 200,
    snEnding: 80000,
    snStep: 1,
    snCircular: 0
  }, {
    id: '80002',
    ordinal: 1,
    datasourceId: 'D0011',
    dataSourceName: '固定值',
    digits: 3,
    constant: 'PH',
    snCurrent: null,
    snBeginning: null,
    snEnding: null,
    snStep: null,
    snCircular: null
  },
];
const departmentDetail = {
  deptName: '环予医疗',
  deptCode: '0',
  nodeInfo: '1',
  subDepts: [
    {
      deptName: 'CT事业部',
      deptCode: 'CT',
      nodeInfo: '1-1',
      subDepts: [
        {
          deptName: '研发部',
          deptCode: 'CT-YF',
          nodeInfo: '1-1-1',
          subDepts: null
        },
        {
          deptName: '生产部',
          deptCode: 'CT-SC',
          nodeInfo: '1-1-2',
          subDepts: null
        },
        {
          deptName: '采购部',
          deptCode: 'CT-CG',
          nodeInfo: '1-1-3',
          subDepts: null
        }
      ]
    },
    {
      deptName: 'MR事业部',
      deptCode: 'MR',
      nodeInfo: '1-2',
      subDepts: [
        {
          deptName: '运营部',
          deptCode: 'MR-YY',
          nodeInfo: '1-2-1',
          subDepts: null
        },
        {
          deptName: '销售部',
          deptCode: 'MR-XS',
          nodeInfo: '1-2-2',
          subDepts: null
        }
      ]
    },
    {
      deptName: 'XT事业部',
      deptCode: 'XT',
      nodeInfo: '1-3',
      subDepts: [
        {
          deptName: '技术部',
          deptCode: 'XT-JS',
          nodeInfo: '1-3-1',
          subDepts: null
        },
        {
          deptName: '后勤部',
          deptCode: 'XT-HQ',
          nodeInfo: '1-3-2',
          subDepts: null
        },
        {
          deptName: '推广部',
          deptCode: 'XT-TG',
          nodeInfo: '1-3-3',
          subDepts: null
        }
      ]
    }
  ]
};

const DataSupplyChainDetail = [{
  id: '00000',
  name: '根节点',
  parent: null,
  level: 0,
  children: [
    {
      id: '00000-1',
      name: '一级子节点A',
      prefix: 'A',
      parent: '00000',
      ordinal: 1,
      level: 1,
      children: [
        {
          id: '00000-1-1',
          name: '二级子节点A01',
          prefix: 'A01',
          snBeginning: 0,
          snEnding: 99,
          snDigits: 4,
          preview: 'A01XXXX',
          parent: '00000-1',
          ordinal: 1,
          level: 2,
          children: []
        }, {
          id: '00000-1-2',
          name: '二级子节点A02',
          prefix: 'A02',
          snBeginning: 100,
          snEnding: 999,
          snDigits: 4,
          preview: 'A02XXXX',
          parent: '00000-1',
          ordinal: 2,
          level: 2,
          children: []
        }
      ]
    }
  ]
}];

// 数据配置--供应链
const DataType = [
  {
    name: '物料',
    value: 'sku',
    children: [
      { name: '物料类别', value: '01' },
      { name: '制造商', value: '02' },
      { name: '物料分级', value: '03' },
      { name: '基本单位', value: '04' },
      { name: '物料属性', value: '05' },
      { name: '库存单位', value: '06' },
      { name: '保质期单位', value: '07' },
      { name: '采购单位', value: '08' },
      { name: '时间单位', value: '09' },
      { name: '销售单位', value: '010' },
      { name: '发料单位', value: '011' },
      { name: '发料方式', value: '012' }
    ]
  },
  {
    name: '仓库',
    value: '1',
    children: [
      { name: '仓库类型', value: '11' },
      { name: '盘点类型', value: '12' },
      { name: '组装拆卸类型', value: '13' },
      { name: '其他入库类型', value: '14' },
      { name: '其他出库类型', value: '15' }
    ]
  },
  {
    name: '供应商',
    value: '2',
    children: [
      { name: '国家', value: '21' },
      { name: '城市', value: '22' },
      { name: '行业', value: '23' },
      { name: '供应商类别', value: '24' },
      { name: '供应商分级', value: '25' },
      { name: '供应商性质', value: '26' },
      { name: '供应商规模', value: '27' },
      { name: '职务', value: '28' },
      { name: '开户银行', value: '29' },
      { name: '证书性质', value: '210' }
    ]
  },
  {
    name: '客户',
    value: '3',
    children: [
      { name: '国家', value: '31' },
      { name: '城市', value: '32' },
      { name: '行业', value: '33' },
    ]
  },
  {
    name: '财务',
    value: '4',
    children: [
      { name: '币种', value: '41' },
      { name: '成本中心', value: '42' },
      { name: '发票类型', value: '43' },
      { name: '默认税率', value: '44' },
      { name: '结算方式', value: '45' }
    ]
  },
];

const DataDetail = [
  { name: '类别A', value: '01', status: `${Math.round(Math.random())}` },
  { name: '类别B', value: '02', status: `${Math.round(Math.random())}` },
  { name: '类别C', value: '03', status: `${Math.round(Math.random())}` },
  { name: '类别D', value: '04', status: `${Math.round(Math.random())}` },
  { name: '类别E', value: '05', status: `${Math.round(Math.random())}` },
  { name: '类别F', value: '06', status: `${Math.round(Math.random())}` }
];
export default {
  // 编码器列表
  getConCodeList: () => ({
    status: 0,
    comment: '描述信息',
    obj: ConCodeList
  }),
  // 编码器数据来源列表
  getCodeDataSource: (config) => {
    const obj = param2Obj(config.url);
    let DataSource = [];
    if (obj.coder === '0001' || obj.coder === '0003') {
      DataSource = DataSource1;
    } else if (obj.coder === '0002') {
      DataSource = DataSource2;
    } else if (obj.coder === '0004' || obj.coder === '0005' || obj.coder === '0006' || obj.coder === '0007') {
      DataSource = DataSource3;
    } else {
      DataSource = DataSource4;
    }
    return {
      status: 0,
      comment: '描述信息',
      obj: {
        coder: obj.coder,
        dataSources: DataSource
      }
    };
  },
  getConCodeDetail: (config) => {
    const obj = param2Obj(config.url);
    return {
      status: 0,
      comment: '描述信息',
      obj: {
        coder: obj.id,
        components: codeDetail
      }
    };
  },
  submitConCodeDetail: (config) => {
    const obj = JSON.parse(config.body);
    console.log(obj);
    return {
      status: 0,
      comment: '成功',
      obj: true
    };
  },
  getCompanyDetail: () => ({
    obj: {
      address: '上海市虹口区赤峰路1号',
      contactNo: '15967896789',
      delFlag: null,
      description: '公司简介啦啦啦啦',
      fax: '021-12345678',
      id: '00000000',
      name: '环予医疗',
      updateUser: '000001',
      website: 'www.huanyu.com',
      zip: '529321'
    }
  }),
  updateCompanyDetail: (config) => {
    console.log(config);
    return {
      status: 0
    };
  },
  getDepartmentsDetail: () => ({
    status: 0,
    obj: departmentDetail
  }),
  updateDepartmentsDetail: (config) => {
    console.log(config);
    return {
      status: 0
    };
  },
  // 数据配置 供应链
  getDataSupplyChainDetail: () => ({
    status: 0,
    obj: DataSupplyChainDetail
  }),
  updateDataSupplyChainDetail: (config) => {
    console.log(config);
    return {
      status: 0
    };
  },
  getDataType: (config) => {
    console.log(config);
    return DataType;
  },
  getDataDetail: (config) => {
    console.log(config);
    return DataDetail;
  },
  saveDataDetail: () => ({
    status: Math.round(Math.random()),
    obj: Math.round(Math.random()),
    comment: '保存失败了~'
  })
};
